<?php
class Letter_model extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    
    public function insert($letter) {
        $this->db->insert('letter', $letter);
        $res = $this->db->affected_rows();
        if ($res > 0) {
            return TRUE;
        } else {
            return FALSE;
        }
    }
    
    public function get_recv($user_id) {
        $this->db->join('user', 'user.user_id = letter.send_id');
        $this->db->from('letter');
        $this->db->where('recv_id', $user_id);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return NULL;
        }
    }
}